include <dimensions.scad>

BABM = ball_assemly_bolt_mount_L;

module sensor_mount() {
  SL = sensor_L;
  
  cube([SL[0], SL[1], SL[2]]);
}

module zr_ball_mount_array(){
  for ( i = [-1 : 1]) {
    rotate(i * 120 + 180)
    translate([ball_radius * sin(zro2_L[1]) - 0.3, 0, ball_radius * cos(zro2_L[1])])
      sphere(d = zro2_L[0]);
  }
}

module finger_hole () {
  translate([5, 0, 5]) 
  rotate([0, 45, 0]) 
  cylinder(30, r = finger_hole_radius);
}


module ball_casing_locks(){
  module lock(){
    union(){
      circle (BABM[0] / 2);
      translate([-BABM[0], -BABM[0] / 2, 0])
      square (BABM[0], BABM[1]);
    }
  }
  linear_extrude(BABM[2]){
    difference(){
      lock();
      translate([0,0,0]) circle(bolt_common_L[0] / 2);
    }
  }
}

module ball_casing_locks_array () {
  for ( i = [-1 : 1]) {
    rotate(i * 120 + 180)
    translate([ball_radius + 0.5 + spacing + BABM[0]/2, 0,-BABM[2]])
    ball_casing_locks();
  }
}



module ball_casing(){
  rotate([0, 180, 0 ]){ // turn upside down
      difference(){
        rotate_extrude(){
          difference(){ // outer shell
            intersection(){ // half sphere
              circle(ball_radius + spacing);
              square(ball_radius + spacing);
            }
            circle(ball_radius); // inner shell
            
          }
        }
    finger_hole();
    zr_ball_mount_array();
    }
  }
  ball_casing_locks_array();
}





// Test zone


#sensor_mount();
ball_casing();